using System;
using System.Diagnostics;
using System.IO;
using System.Collections.Generic;
using org.tmatesoft.svn.core;
using org.tmatesoft.svn.core.wc;

namespace Subsync.Core.Subversion
{
	/// <summary>
	/// Author: Hoang Duc
	/// </summary>
	public class SVNAdd : CommandBase
	{
        /// <summary>
        /// We have our variables declared here.
        /// Access modifiers as you can observe, is public. Why?
        /// Because we trust our programmers.
        /// 
        /// Try to be verbose with the variable names.
        /// Also, try to include *sane defaults*. Take peg_revision for eg.
        /// </summary>
        private java.io.File path;
        private bool force = false;
        private bool mkdir = false;
        private bool climbUnversionedParents;
        private SVNDepth depth = SVNDepth.INFINITY;
        private bool includeIgnored = false;
        private bool makeParents = false;

        /// <summary>
        /// Default constructor.
        /// </summary>
        public SVNAdd()
        {
        }

        /// <summary>
		/// Minimal constructor for unit tests.
		/// </summary>
		/// <param name="path">
		/// A <see cref="System.String"/>
		/// </param>
        public SVNAdd(string location, bool force)
		{
            this.path = new java.io.File(location);
            this.force = force;
		}

        /// <summary>
        /// Minimal constructor
        /// </summary>
        /// <param name="path">
        /// A <see cref="java.io.File"/>
        /// </param>
        /// <param name="force">
        /// A <see cref="System.Boolean"/>
        /// </param>
        /// <param name="climbUnversionedParents">
        /// A <see cref="System.Boolean"/>
        /// </param>
        /// <param name="depth">
        /// A <see cref="SVNDepth"/>
        /// </param>
        /// <param name="includeIgnored">
        /// A <see cref="System.Boolean"/>
        /// </param>
        /// <param name="makeParents">
        /// A <see cref="System.Boolean"/>
        /// </param>
        public SVNAdd(java.io.File path, bool force, bool mkdir, bool climbUnversionedParents, SVNDepth depth, bool includeIgnored, bool makeParents)
        {
            this.path = path;
            this.force = force;
            this.climbUnversionedParents = climbUnversionedParents;
            this.depth = depth;
            this.includeIgnored = includeIgnored;
            this.makeParents = makeParents;
        }

        public override void Execute()
		{
            Debug.WriteLine("SVN Add Execution");

            //library setup
            Tools.SetupLibrary();

            //load up the clients
            SVNClientManager cm = SVNClientManager.newInstance();
            SVNWCClient wcc = cm.getWCClient();

            try
            {
                wcc.doAdd(this.path, this.force, this.mkdir, this.climbUnversionedParents, 
                    this.depth, this.includeIgnored, this.makeParents);
            }
            catch (SVNException e)
            {
                //we convert this exception to a non SVNKit exception.
                //we want to minimize interfacing with SVNkit outside of this namespace (abstraction)
                throw new SVNExecuteException(e.getMessage());
            }
		}
	}
}
